GDIR=../../..

CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
INCLUDES=-I$(UTILSPATH) -I$(MACIPATH) -I../ASRoboBus -Iinclude 
CFLAGS=-O0 -g3 $(INCLUDES) $(CE) \
	$(EXTRADEFS)
CPPQUALITYFLAGS=-Wall -Weffc++
CPPFLAGS=-O0 -g3  $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=-lrt -lpthread

# Sources 'base' (required external links)
SRCSC=$(UTILSPATH)/owndebug.c $(UTILSPATH)/ownutils.c $(GDIR)/utils/crc16.c
SRCSCPP=../ASRoboBus/ASRoboBus.cpp \


DIRTYSRCSCPP= include/ecanlib.cpp \
	      ecanTest.cpp \
              ecan1000hr.cpp
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)
DIRTYOBJSCPP=$(DIRTYSRCSCPP:.cpp=.dopp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPQUALITYFLAGS) -c
COMPILEDIRTYCPP=$(CXX) $(CPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all:	ECan1000hr

# Rules
ECan1000hr:	$(OBJSC) $(OBJSCPP) $(DIRTYOBJSCPP)
		$(LINK) -o $@ $(OBJSC) $(OBJSCPP) $(DIRTYOBJSCPP)
		@echo "      [LD] $@"
clean:
	rm -f $(OBJSC) $(OBJSCPP) $(DIRTYOBJSCPP) 

# Compile rule for all .o (.c) file
%.o:	%.c
	$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"
# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	$(COMPILECPP) -o $@ $<
	@echo "      [CC] $<"	
# Compile rule for all .dopp dirty (.cpp) files
%.dopp:	%.cpp
	@$(COMPILEDIRTYCPP) -o $@ $<
	@echo "      [DIRTY-CC] $<"